﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Main.aspx.cs" Inherits="Main" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" style="height: 100%">
<head runat="server">
    <title>教学质量监测系统-基础数据管理</title>
    <link href="Common/css/main.css" rel="stylesheet" type="text/css" />


    <script type="text/javascript" src="Common/js/jquery.js"></script>

    <script type="text/javascript" src="Common/js/jsUtil.js"></script>

    <script type="text/javascript" src="Common/js/common.js"></script>
    
    <script type="text/javascript" src="Common/js/My97DatePicker/WdatePicker.js"></script>
    <style type="text/css">
    div{_behavior: url("Common/css/iepngfix.htc") }
</style>
    <script type="text/javascript">
    
    //显示年级升级对话框
    function Load()
    {
        InitOptList("popSchoolOpt","请选择");
        InitSchYear();
        
        
        var type = <%= EduType %>;
        if (type == 1) {
            PageMethods.ValidYearTeam(function(succ)
            {
                if (succ > 0)
                {
                    ShowTermUpgrade();
                }        
            })
        }
    }
    
    function InitSchYear()
    {    
        var selectYear = document.getElementById('selectYear');
        
        //清空
        while(selectYear.options.length)
        {
            selectYear.options.remove(0);
        }

        //初始化学年下拉框
        var years = ['2003 - 2004学年', '2004 - 2005学年', '2005 - 2006学年', '2006 - 2007学年', '2007 - 2008学年', '2008 - 2009学年', '2009 - 2010学年',
                     '2010 - 2011学年', '2011 - 2012学年', '2012 - 2013学年', '2013 - 2014学年', '2014 - 2015学年', '2015 - 2016学年', '2016 - 2017学年', 
                     '2017 - 2018学年', '2018 - 2019学年', '2019 - 2020学年', '2020 - 2021学年'];
        for(var i = 0; i < years.length;i++)
        {
            var oOption = document.createElement("OPTION");
            oOption.text=years[i];
            oOption.value=2003+i;
            selectYear.add(oOption);
        }
        
        var nowYear = GetNowYear();
        if (nowYear>2020 || nowYear<2003)
            selectYear.value = 2003;
        else
            selectYear.value = nowYear;
        showSchoolInfoForm();
    }
    
    function InitOptList(selOptId,firstText)
    {
        var selectOpt = document.getElementById(selOptId);
        
        //清空
        while(selectOpt.options.length)
        {
            selectOpt.options.remove(0);
        }

        var grades=  ['小学', '初中', '高中', '小学、初中', '初中、高中', '小学、初中、高中'];
        var oOption = document.createElement("OPTION");
        oOption.text=firstText;
        oOption.value= 0;
        selectOpt.add(oOption);
        
        for(var i = 0; i < grades.length;i++)
        {
            var oOption = document.createElement("OPTION");
            oOption.text=grades[i];
            oOption.value=i+1;
            selectOpt.add(oOption);
        } 
        
        selectOpt.value = 0;
    }
    
    function ShowTermUpgrade()
    {
        //初始化学校学部列表
        InitSchoolDept();
    
        //显示添加教师信息对话框        
        ShowPopForm("popTable", "formTitle", "学期升级");
        //显示背景遮罩
        showMask();
    }
    
    //显示修改密码窗口
    function ShowUpdatePassword()
    {
        document.getElementById('pwd').value='';
        document.getElementById('newpwd1').value='';
        document.getElementById('newpwd2').value='';
        //显示修改密码对话框        
        ShowPopForm("upPwdPop", "upPwdPopTitle", "修改密码");
        //显示背景遮罩
        showMask();
    }

    //关闭学期升级对话框
    function CloseMask(formId)
    {
        ClosePopForm(formId,true);
        hideMask();
    }

    function TermUpgrade()
    {
        var arr = GetSchoolDeptList();
//        for (var i = 0; i < arr.length; i++)
//        {
//            alert(arr[i]);
//        }
        
        PageMethods.TermUpgrade(arr,function(succ){
            if (succ == 1)
            {
                showMassgeBox("提示","学期升级成功",1,null);
            }
            if (succ == 2)
            {
                showMassgeBox("提示","无需升级学期",1,null);
            }            
            if (succ == 0)
            {
                showMassgeBox("提示","学期升级失败",1,null);
            }                  
            CloseMask('popTable');
        },function(err){//异步失败
            showMassgeBox("提示","学期升级失败，请刷新重试",1,null);
        });
    }
    
    //点击更新按钮
    function UpdatePassword()
    {
        var pwd = document.getElementById('pwd');
        var newpwd1 = document.getElementById('newpwd1');
        var newpwd2 = document.getElementById('newpwd2');
        if(pwd.value=="")
        {
        
            showNoticMsg('pwd', '密码不能为空');
            pwd.focus();
            return;
        }
        if(newpwd1.value=="")
        {
            showNoticMsg('newpwd1', '新密码不能为空');
            newpwd1.focus();
            return;
        }
         if(newpwd2.value=="")
        {
            showNoticMsg('newpwd2', '确认密码不能为空');
            newpwd2.focus();
            return;
        }
        
        if (getStringCount(pwd.value) >20)
        {
            showNoticMsg('pwd','密码不能大于20个字符');
            pwd.focus();              
            return;
        }
        
         if (getStringCount(newpwd1.value) >20)
        {
            showNoticMsg('newpwd1','密码不能大于20个字符');
            newpwd1.focus();              
            return;
        }
        
        if (getStringCount(newpwd2.value) >20)
        {
            showNoticMsg('newpwd2','密码不能大于20个字符');
            newpwd2.focus();              
            return;
        }
        
        if (containSpecialChar(pwd.value) == true)
        {
            showNoticMsg('pwd','密码不能含有特殊字符');
            pwd.focus();               
            return;
        }
        
        if (containSpecialChar(newpwd1.value) == true)
        {
            showNoticMsg('newpwd1','密码不能含有特殊字符');
            newpwd1.focus();               
            return;
        }
        
        if (containSpecialChar(newpwd2.value) == true)
        {
            showNoticMsg('newpwd2','密码不能含有特殊字符');
            newpwd2.focus();  
            return;
        }
                                
        
        if(newpwd2.value!=newpwd1.value)
        {
            newpwd1.value = '';
            newpwd2.value = '';
            showNoticMsg('newpwd1','新密码和确认密码必须相同');
            newpwd1.focus();
            return;
        }
        
        PageMethods.UpdatePwd(pwd.value, newpwd1.value, function(result){
            
            if(result > 0)
            {
                showMassgeBox("提示", '修改密码成功');
                ClosePopForm('upPwdPop');
            }
            else if (result == -1)
            {
                pwd.value = '';
                showNoticMsg('pwd','原密码不正确，请重新输入');
                pwd.focus();
            }
            else
            {
                pwd.value = '';
                showNoticMsg('pwd','修改密码失败，请重新修改');
                pwd.focus();
            }

        },function(err){ 
            showMassgeBox("提示",UPDATEPWD_EXCEPTION,1,null);
        });
        
    }
    
    function Logout()
    {
        top.location="../logout.aspx";
    }

    function ReturnNav()
    {
	    top.location="../main.aspx";
    }
    
//初始化学校学部列表
function InitSchoolDept()
{
    var table = document.getElementById('TABLEDept');

    //当前学校信息
    PageMethods.GetSchoolInfo(function(succ){
        if (succ != null)
        {
            switch (succ.SchoolOpt)
            {
                //小学
                case 1:
                    table.style.display = "none";   
                    document.getElementById('CHKDept1').checked = true;
                    document.getElementById('CHKDept2').checked = false;
                    document.getElementById('CHKDept3').checked = false;
                    break;
                //初中                    
                case 2:
                    table.style.display = "none";   
                    document.getElementById('CHKDept1').checked = false;
                    document.getElementById('CHKDept2').checked = true;
                    document.getElementById('CHKDept3').checked = false;
                    break; 
                //高中                   
                case 3:
                    table.style.display = "none"; 
                    document.getElementById('CHKDept1').checked = false;
                    document.getElementById('CHKDept2').checked = false;
                    document.getElementById('CHKDept3').checked = true;
                    break;
                //小学、初中
                case 4:
                    document.getElementById('TDDept3').style.display = "none";
                    document.getElementById('CHKDept3').checked = false;
                    break;
                //初中、高中
                case 5:
                    document.getElementById('TDDept1').style.display = "none";
                    document.getElementById('CHKDept1').checked = false;
                    break;
                //小学、初中、高中
                case 6:
                    break;
            }
        }
    },function(err){//异步失败
        showMassgeBox("提示","获取学校信息失败，请刷新重试",1,null);
    });
}
	
//获取用户所选择需要升级的学校学部
function GetSchoolDeptList()
{  
    var arr = new Array(0,0,0);
    if(document.getElementById("TABLEDept") != null)
    {
        var checkItems=document.getElementById("TABLEDept").getElementsByTagName('input');
        for(var i=0;i < checkItems.length;i++){
　　        var checkItem= checkItems[i];
　　        if(checkItem.type==='checkbox' && checkItem.checked)
　　        {
　　            var i = parseInt(checkItem.deptno)
　　            arr[i] = 1;
　　        }
        }
    }
    return arr;
}

function showSchoolInfoForm() {
    var flag = <%= CheckSchoolInfoInitState %>;
    var type = <%= EduType %>;
    if (flag == 0 && type == 0) {
        ShowPopForm("divSchoolSettings", "spanSchoolSettings", "设置学校信息");
    }
}

function checkSchoolForm() {
    var txtSchoolName = document.getElementById("txtSchoolName");
    if (txtSchoolName.value.trim() == "") {
        showNoticMsg("txtSchoolName", "请输入学校名");
        return false;
    }    
    
    var popSchoolOpt = document.getElementById("popSchoolOpt");
    if (popSchoolOpt.selectedIndex == 0) {
        showNoticMsg("popSchoolOpt", "请选择学校性质");
        return false;
    }    
    
    return true;
}

// 保存学校信息
function SaveSchoolInfo() {
    if (!checkSchoolForm()) return;
    var schoolName = document.getElementById("txtSchoolName").value.Trim();
    var year = parseInt(document.getElementById('selectYear').value.Trim());
    var term = parseInt(document.getElementById('selectTerm').value.Trim());
    var schoolOpt = parseInt(document.getElementById("popSchoolOpt").value.Trim());
    
    var startDate = document.getElementById("txtStartDate").value;
    var endDate = document.getElementById("txtEndDate").value;
    if(startDate == null || startDate.length < 1) {
        showMassgeBox("提示","请设定学期开始日期",1,null);
        return;
    }
    
    PageMethods.SaveSchoolInfo(schoolName, year, term, schoolOpt, startDate, endDate, 
        function (succ) {
            ClosePopForm("divSchoolSettings");
            var tdSchoolName = document.getElementById("tdSchoolName");
            tdSchoolName.innerHTML = schoolName+" 基础数据管理系统";
            //window.location.reload();
        }
    );
    
}

function setSchoolName(schoolName) {
    document.getElementById("tdSchoolName").innerHTML = schoolName+" 基础数据管理系统";
}
    function Format()
    {
        var c=document.body.scrollHeight;
        if((c-68-50)>0)
        {
            document.getElementById("contentH").style.height=(c-68-50)+"px";
            document.getElementById("leftFrame").style.height=(c-68-50)+"px";
            document.getElementById("mainFrame").style.height=(c-68-50)+"px";
        }
    }
    </script>

</head>
<body scroll="no" onload="Load();" style="height: 100%" onresize="Format();">
    <form id="form1" runat="server" style="height: 100%">
        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="True">
        </asp:ScriptManager>
        <div class="bodyWarp" style="height: 100%" id="c">
            <div class="pageHea">
                <div class="navHea">
  			    <table border="0" cellspacing="0" cellpadding="0" style="width:99%;">
                    <tr>
                        <td rowspan="2" style="padding-top:12px;width:50%;font-family:微软雅黑;"><h2 id="tdSchoolName"> <%=CommonScore.SchoolName%> 基础数据管理系统 </h2>
                        </td>
                        <td style="width:50%;text-align:right;"><img src="Common/images/top_2.gif" align="absmiddle" style="float: none;" />
                                <a href="javascript:ReturnNav()" title="">首页</a>&nbsp;&nbsp;
                                <img src="Common/images/updatepass.gif" align="absmiddle" style="float: none;" />
                                <a href="javascript:ShowUpdatePassword()" title="">修改密码</a>&nbsp;&nbsp;
                                <img src="Common/images/logout.gif" align="absmiddle" style="float: none;" />
                                <a class="red" href="javascript:Logout()" title="">退出</a>
                        </td>
                    </tr>
                    <tr>
                        <td style="text-align:right;">用户：<%= CommonScore.GetUserName %>(<%= CommonScore.GetUserCode %>)&nbsp;&nbsp;&nbsp;<% if (Common.CurrentVersion != EduVersion.School)
                                  { %>角色：教育局管理员
                                  <% }
                                      else
                                  {%>角色：学校管理员
                                  <% } %> &nbsp;&nbsp; 当前:<%= GetNowYearAndTerm %>
                        </td>
                    </tr>
                </table>
                    
                </div>
                <div class="menuHea">
                </div>
            </div>
            <div class="pageBody" id="contentH">
                <div class="pageLeft" id="div1">
                    <iframe name="leftFrame" src="Left.aspx" style="height: 100%; width: 100%; overflow: auto;"
                        frameborder="0" marginwidth="0" marginheight="0"></iframe>
                </div>
                <div class="pageMain" id="div2">
                    <iframe name="mainFrame" src="Welcome.htm" style="height: 100%; width: 100%" frameborder="0"
                        border="0" marginwidth="0" marginheight="0"></iframe>
                </div>
            </div>
	        <div class="pageFoot">
    	        <a href="http://www.juwangtech.com/" title="武汉聚网科技有限公司">武汉聚网科技有限公司</a> 版权所有 @2009  全国免费服务热线：800-713-6688 电子邮箱：service@juwangtech.com
            </div>
            <!--END-->
        </div>
    </form>
    <!--弹出学年升级对话框-->
    <div id="popTable" class="layoutWarp" style="display: none; width: 300px; overflow: inherit;">
        <div class="title">
            <span id="formTitle">新增</span>
            <!--<a title="关闭" > 关闭</a>-->
        </div>
        <table id="tableCauseObject" style="width: 280px; margin-top: 12px;" border="0" class="layoutTable">
            <tr>
                课程变化：保留原课程
            </tr>
            <tr>
                学生升留级：整体升级
            </tr>
            <tr>
                教师跟班：跟班
            </tr>
            <tr>
                班主任跟班：跟班
            </tr>
            <!-- 权限部分 -->
            <tr>
                <td valign="top">
                    <table id="TABLEDept" style="width: 100%; text-align: left;" border="0">
                        <tr>
                            <td id="TDDeptHeader" colspan="3">
                                请选择需要学年升级的学部：</td>
                        </tr>
                        <tr>
                            <td id="TDDept1">
                                <input type="checkbox" deptno="0" id="CHKDept1" checked /><font title="选择升级小学部">&nbsp;小学部</font></td>
                            <td id="TDDept2">
                                <input type="checkbox" deptno="1" id="CHKDept2" checked /><font title="选择升级初中部">&nbsp;初中部</font></td>
                            <td id="TDDept3">
                                <input type="checkbox" deptno="2" id="CHKDept3" checked /><font title="选择升级高中部">&nbsp;高中部</font></td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
                <td colspan="3" align="center">
                    <ul class="butList">
                        <input type="button" id="btnSave" value="升级" onclick="TermUpgrade()" class="commonBut" />
                        <!--<input type="button" value="取消" class="commonBut" />-->
                    </ul>
                </td>
            </tr>
        </table>
    </div>
    <!--END-->
    <!-- 添加/修改题目分类弹出对话框 -->
    <div id="upPwdPop" class="layoutWarp" style="display: none; width: 400px;">
        <div class="title">
            <span id="upPwdPopTitle"></span><a title="关闭" onclick="return ClosePopForm('upPwdPop')">
                关闭</a>
        </div>
        <table border="0" class="layoutTable">
            <tr>
                <td width="107" align="right">
                    原密码：</td>
                <td width="213" align="left">
                    <input onkeydown="" id="pwd" class="textInput" onfocus="" maxlength="20" type="password" /></td>
            </tr>
            <tr>
                <td width="107" align="right">
                    新密码：</td>
                <td width="213" align="left">
                    <input onkeydown="" id="newpwd1" class="textInput" onfocus="" maxlength="20" type="password" /></td>
            </tr>
            <tr>
                <td width="107" align="right">
                    确认新密码：</td>
                <td width="213" align="left">
                    <input onkeydown="" id="newpwd2" class="textInput" onfocus="" maxlength="20" type="password" /></td>
            </tr>
            <tr>
                <td colspan="2">
                    <div align="center">
                        <input name="btnReqClsOK" type="button" class="commonBut" id="btnReqClsOK" onclick="UpdatePassword();"
                            value="确定" />
                        <input name="btnReqClsCancel" type="button" class="commonBut" id="btnReqClsCancel"
                            onclick="return CloseMask('upPwdPop')" value="取消" />
                    </div>
                </td>
            </tr>
        </table>
    </div>
    <!--END-->
    <!-- 设置学校信息 -->
    <div id="divSchoolSettings" class="layoutWarp" style="display: none; width: 400px;">
        <div class="title">
            <span id="spanSchoolSettings"></span>
        </div>
        <table border="0" class="layoutTable">
            <tr>
                <td style="text-align: right; width: 35%;">
                    学校名:</td>
                <td>
                    <input onkeydown="" id="txtSchoolName" class="textInput" onfocus="" maxlength="20"
                        type="text" style='width: 120px;' />&nbsp;&nbsp;<span style="color: red">*</span>
                </td>
            </tr>
            <tr>
                <td style="text-align: right; width: 35%;">
                    学年:
                </td>
                <td>
                    <select id="selectYear" style='width: 120px;'>
                    </select>
                    &nbsp;&nbsp;<span style="color: red">*</span>
                </td>
            </tr>
            <tr>
                <td style="text-align: right; width: 35%;">
                    学期:</td>
                <td>
                    <select id="selectTerm" style='width: 120px;'>
                        <option value="1" selected>上学期</option>
                        <option value="2">下学期</option>
                    </select>
                    &nbsp;&nbsp;<span style="color: red">*</span>
                </td>
            </tr>
            <tr>
                <td style="text-align: right; width: 35%;">
                    学校性质:</td>
                <td>
                    <select id="popSchoolOpt" style="width: 120px">
                    </select>
                    &nbsp;&nbsp;<span style="color: red">*</span>
                </td>
            </tr>
            <tr>
                <td style="text-align: right; width: 35%;">
                    <span>学期开始日期: </span>
                </td>
                <td>
                    <input readonly="readonly" style="width: 120px" maxlength="20" name="text" type="text" class="txtStyle" id="txtStartDate" onfocus="WdatePicker({skin:'whyGreenSmall',dateFmt:'yyyy/MM/dd'})"/>
                    &nbsp;&nbsp;<span style="color: red">*</span>
                    
                </td>
            </tr>
            <tr>
                <td style="text-align: right; width: 35%;">
                    <span>&nbsp;&nbsp;学期截止日期: </span>
                </td>
                <td>
                    <input readonly="readonly" style="width: 120px" maxlength="20" name="text" type="text" class="txtStyle" id="txtEndDate" onfocus="WdatePicker({skin:'whyGreenSmall',dateFmt:'yyyy/MM/dd'})"/>
                    &nbsp;&nbsp;&nbsp;
                </td>
            </tr>
            <tr>
                <td colspan="2" style="text-align: center;">
                    <input type="button" id="btnSaveSchoolInfo" value="保存" onclick="SaveSchoolInfo()"
                        class="commonBut" />
                </td>
            </tr>
        </table>
    </div>
    <!--END-->
</body>

<script language="javascript" type="text/javascript">
Format();


//alert(document.body.scrollHeight);
</script>

</html>
